﻿using System;
using HttpApiGateway;
using HttpApiGateway.Model;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Controller
{
        /// <summary>
        /// 节点版本路由规则
        /// </summary>
        internal class VerRouteController : ApiController
        {
                private readonly IVerRouteService _Service;
                public VerRouteController (IVerRouteService service)
                {
                        this._Service = service;
                }
                /// <summary>
                /// 添加版本路由规则
                /// </summary>
                /// <param name="add"></param>
                /// <returns></returns>
                public Guid Add (VerRouteDatum add)
                {
                        return this._Service.Add (add);
                }
                /// <summary>
                /// 删除版本路由规则
                /// </summary>
                /// <param name="id"></param>
                public void Delete ([NullValidate ("rpc.ver.route.id.null")] Guid id)
                {
                        this._Service.Delete (id);
                }
                /// <summary>
                /// 获取版本路由规则
                /// </summary>
                /// <param name="id"></param>
                /// <returns></returns>
                public ServiceVerRoute Get ([NullValidate ("rpc.ver.route.id.null")] Guid id)
                {
                        return this._Service.Get (id);
                }
                /// <summary>
                /// 获取版本下所有的路由规则
                /// </summary>
                /// <param name="verId"></param>
                /// <returns></returns>
                public VerRoute[] Gets ([NumValidate ("rpc.ver.id.error", 1)] long verId)
                {
                        return this._Service.GetRoutes (verId);
                }
                /// <summary>
                /// 设置指定的路由规则
                /// </summary>
                /// <param name="set"></param>
                public void Set (GuidParam<VerRouteSet> set)
                {
                        this._Service.Set (set.Id, set.Param);
                }
                /// <summary>
                /// 禁用或启用版本路由
                /// </summary>
                /// <param name="param"></param>
                public void SetIsEnable (GuidParam<bool> param)
                {
                        this._Service.SetIsEnable (param.Id, param.Param);
                }
        }
}
